package com.servlet.type;

import com.dao.TypeDao;
import com.dao.TypeInfo;
import com.dao.UserInfo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

/**
 * @author admin
 */
@WebServlet(name = "TypeUpdateServlet",urlPatterns = "/TypeUpdateServlet.filter")
public class TypeUpdateServlet extends HttpServlet {
//    private String encoding;


    private TypeDao typeDao = new TypeInfo();


    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("TypeUpdateServlet");
        String t_id = request.getParameter("t_id");
        String t_name = request.getParameter("t_name");
        System.out.println(t_id+t_name);
        try {
            boolean b = typeDao.updateType(Integer.parseInt(t_id),t_name);
            if (b){
                System.out.println("类型修改成功");
                response.sendRedirect(request.getContextPath()+"/TypeSelectAllServlet.filter");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
